package sistkaraoke.servlet.reserva;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sistkaraoke.modelo.ICliente;
import sistkaraoke.modelo.IReserva;
import sistkaraoke.modelo.ISala;
import sistkaraoke.negocio.GestionReserva;
import sistkaraoke.negocio.GestionSalas;
import sistkaraoke.negocio.IGestionReserva;
import sistkaraoke.negocio.IGestionSalas;

/**
 * Servlet implementation class BuscarReservaServlet
 */
@WebServlet("/BuscarReservaServlet")
public class BuscarReservaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuscarReservaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		try {	
			
			int idAdmin = Integer.parseInt(request.getParameter("ID"));
			String descripcion = request.getParameter("txtdescripcion").trim();
			String vIdSala=request.getParameter("sala").trim();
			String vIdCliente=request.getParameter("cliente");
			
			int idSala=0;
			
			if(vIdSala.length()>0){
				idSala=Integer.parseInt(vIdSala);
			}
			
			int idCliente;
			idCliente=0;
			
			if(vIdCliente.length()>0){
				idCliente=Integer.parseInt(vIdCliente);
			}
					
			IGestionReserva negocio = new GestionReserva();

						
			if (descripcion.trim().length() > 0)
				request.setAttribute("reservas_registradas", ((Collection<IReserva>) negocio.buscarPorDescripcion(descripcion)));
			else if (idSala > 0)
				request.setAttribute("reservas_registradas", ((Collection<IReserva>) negocio.buscarPorSala(idSala)));

			request.setAttribute("IdSalaSelected", vIdSala.toString());
			RequestDispatcher rd = request.getRequestDispatcher("BuscarReserva.jsp");
			
			rd.forward(request, response);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
	}

}
